using CGF;
using UnityEngine;
using UnityEngine.UI;

public class TabMeCtrl : MonoBehaviour
{
    private TabMe TabMe;
    public static bool AutoPushMsg
    {
        get { return PlayerPrefs.GetInt("AutoPushMsg") == 1; }
        set { PlayerPrefs.SetInt("AutoPushMsg", value ? 1 : 0); }
    }

    private void Awake()
    {
        TabMe = new TabMe();
        TabMe.BindProperties(transform);
        
        TabMe.CellInfo.SetClick(() =>
        {
            PanelPersonalInfo.Open();
        });
        TabMe.CellContact.SetClick(() =>
        {
            PanelContactMyService.Open();
        });
        TabMe.CellMyTrain.SetClick(() =>
        {
            PanelMyTraining.Open();
        });
        TabMe.CellExpo.SetClick(() =>
        {
            PanelMyExpo.Open();
        });
        TabMe.CellWithdraw.SetClick(() =>
        {
            PanelWithdrawRecords.Open();
        });
        TabMe.CellInvite.SetClick(() =>
        {
            PanelMyInvites.Open();
        });

        TabMe.FAQ.SetClick(() =>
        {
            PanelFAQ.Open();
        });
        TabMe.AbountUs.SetClick(() =>
        {
            Application.OpenURL(Config.Get.AboutUsUrl);
        });
        TabMe.SwitchPushMsg.SetIsOn(AutoPushMsg, false);
        TabMe.SwitchPushMsg.onStateChanged = isOn =>
        {
            AutoPushMsg = isOn;
        };
        TabMe.Language.SetClick(() =>
        {
            PanelEditLanguage.Open();
        });
        TabMe.Version.SetClick(() =>
        {
            Dialog.Alert(TabMe.I18N_curr_is_latest_version);
        });

        TabMe.BtnLogout.SetClick(() =>
        {
            UserInfo.OnLogout();
            GameUI.Close();
            LoginUI.Open();
        });

        TabMe.Version.gameObject.Get<Text>("Title").text = TabMe.I18N_version + " v " + CGFConfig.Instance.VersionFullName;
    }
}
